package com.xckj.teacher.ui.activity

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.xckj.teacher.R
import com.xckj.teacher.databinding.ActivityHomeworkReportBinding
import com.xckj.teacher.framework.BaseActivity
import com.xckj.teacher.ui.fragment.HomeWorkFragment
import com.xckj.teacher.util.get


/**
 * 课后作业报告
 */
class HomeworkReportActivity : BaseActivity<ActivityHomeworkReportBinding>() {

    var className = ""

    var titles: ArrayList<String> = ArrayList() //放标题

    var fragments: ArrayList<HomeWorkFragment> = ArrayList() //放fragment

    override fun setStatusBarColor(): Int {
        return R.color.white
    }

    inner class ProxyClick {
        fun back() {
            finish()
        }

    }


    override fun loadLayout(): Int {
        return R.layout.activity_homework_report
    }

    override fun initData() {
        dataBinding.click = ProxyClick()

        var classId = intent.get<String>("classId") ?: ""
        className = intent.get<String>("className") ?: ""

        titles.add("听说模考")
        titles.add("单词跟读")
        titles.add("语文跟读")
        titles.add("线上作答")

        titles.forEach {
            fragments.add(HomeWorkFragment(it, classId, className))
            dataBinding.tabPic.addTab(dataBinding.tabPic.newTab().setText(it))
        }
        dataBinding.viewPager.setAdapter(ViewPagerAdapter(getSupportFragmentManager()));
        dataBinding.tabPic.setupWithViewPager(dataBinding.viewPager)
    }

    override fun setListener() {
        dataBinding.tabPic.addOnTabSelectedListener(object : OnTabSelectedListener {
            override fun onTabSelected(p0: TabLayout.Tab?) {

            }

            override fun onTabUnselected(p0: TabLayout.Tab?) {

            }

            override fun onTabReselected(p0: TabLayout.Tab?) {

            }

        })
    }

    inner class ViewPagerAdapter(fm: FragmentManager?) :
        FragmentStatePagerAdapter(fm!!) {
        override fun getItem(position: Int): Fragment {
            return fragments[position]
        }

        override fun getCount(): Int {
            return fragments.size
        }

        override fun getPageTitle(position: Int): CharSequence {
            return titles[position]
        }
    }

}